//
//  LoginViewModel.swift
//  RAC-Swift-Demo
//
//  Created by LuckyStrike on 2018/7/31.
//  Copyright © 2018年 LuckyStrike. All rights reserved.
//

import Foundation
import ReactiveSwift
import Result
import UIKit

struct FormError: Error {
    let reason: String
    
    static let invalidEmail = FormError(reason: "The address must end with `@reactivecocoa.io`.")
    static let mismatchEmail = FormError(reason: "The e-mail addresses do not match.")
    static let usernameUnavailable = FormError(reason: "The username has been taken.")
}

class LoginViewModel: NSObject {
    
    var userName : ValidatingProperty<String,FormError>
    
    let password : ValidatingProperty<String,FormError>
    
    let termsAccepted : MutableProperty<Bool>
    
    let submit : Action< (), (),FormError>
    
    let reasons : Signal<String,NoError>
    
    override init() {
        
        
        userName = ValidatingProperty("", { $0.count > 0 ? .valid : .invalid(.invalidEmail) })
        password = ValidatingProperty("", with: userName, { input,userName in
            return input == userName ? .valid : .invalid(.invalidEmail)
        })
        termsAccepted = MutableProperty(flase)
        
        let submitEmail = Property(
        
        
        submit = Action(unwrapping: <#T##PropertyProtocol#>, execute: <#T##(T) -> SignalProducer<_, _>#>)
        
        
        super.init()
    }
    
    
    
    
    
    
}
